/**
 * 
 */
package com.mbengue.corp.apr.ra.dao.impl;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Expression;

import com.mbengue.corp.apr.ra.core.Evenement;
import com.mbengue.corp.apr.ra.dao.EvenementDao;
import com.mbengue.corp.apr.ra.util.HibernateUtil;

/**
 * @author MMB11447
 *
 */
public class EvenementDaoImpl implements EvenementDao, Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private Session session;
	
	public EvenementDaoImpl() {
		session = HibernateUtil.getSessionFactory();
	}

	/* (non-Javadoc)
	 * @see com.mbengue.corp.apr.ra.dao.EvenementDao#ajouterEvenement(com.mbengue.corp.apr.ra.core.Evenement)
	 */
	public void ajouterEvenement(Evenement evenement) throws HibernateException {
		Transaction transaction = session.beginTransaction();
		try {
			session.save(evenement);
			transaction.commit();
		} catch (Exception e) {
			transaction.rollback();
			throw new HibernateException(e);
		} finally {
			session.flush();
			session.close();
		}
	}

	/* (non-Javadoc)
	 * @see com.mbengue.corp.apr.ra.dao.EvenementDao#trouverEvenement(long)
	 */
	public Evenement trouverEvenement(long id) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.mbengue.corp.apr.ra.dao.EvenementDao#trouverEvenementParTitre(java.lang.String)
	 */
	public List<Evenement> trouverEvenementParTitre(String titre) {
		// TODO Auto-generated method stub
		return null;
	}

	@SuppressWarnings("unchecked")
	public List<Evenement> trouverEvenementParDates(Date debut, Date fin) {
		Criteria criteria = session.createCriteria(Evenement.class);
		criteria.add(Expression.between("debut", debut, fin));
		
		return criteria.list();
	}

}
